<template>
  <!-- 添加或修改生产记录对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="退回原因" prop="refuseReason">
            <el-input v-model="form.refuseReason" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "ProduceRecordRefuseStoreForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        produceDate: [
          {required: true, message: "生产日期不能为空", trigger: "blur"}
        ],
        submitDate: [
          {required: true, message: "提交日期不能为空", trigger: "blur"}
        ],

      },
      url: {
        getById: '/produceRecord/produceRecord/',
        add: '/produceRecord/produceRecord/add',
        storeReturn: '/produceRecord/produceRecord/storeReturn',
      },
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nos: null,
        produceDate: null,
        submitDate: null,
        status: "0",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleRefuse(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.status = "5";
        this.title = "库管退回";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.storeReturn, this.form).then(response => {
              this.$modal.msgSuccess("退回成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
